package com.henu.engineer.controller.general

import com.alibaba.fastjson.JSONObject
import com.henu.engineer.service.LoginService
import com.henu.engineer.service.CultivatingProjectService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

/**
 * 查看培养方案的api
 * @author noexcept
 * @since 2021/8/11 0:11
 */
@RestController
@RequestMapping("/ga")
class CultivatingProjectController {

    @Autowired
    lateinit var cultivatingProjectService: CultivatingProjectService

    @Autowired
    lateinit var loginService:LoginService

    /**
     * 查询培养目标
     */
    @GetMapping("/cultivatingGoal")
    fun getCultivatingGoalsBySpecAndVersion(): String {
        val res = JSONObject()
        if (loginService.currentTeacher == null && loginService.currentStudent == null) {
            res["code"] = 1
            res["msg"] = "用户暂未登陆"
            return res.toJSONString()
        }
        res["code"] = 1
        res["msg"] = "success"
        res["result"] = cultivatingProjectService.getCultivatingGoalsBySpecAndVersion()

        return res.toJSONString()
    }

    /**
     * 获取当前用户的对应专业和有效版本的毕业要求
     */
    @GetMapping("/graduationRequirement")
    fun getGraduationRequirementBySpecAndVersion(): String {
        val res = JSONObject()

        res["code"] = 1
        res["msg"] = "success"
        res["result"] = cultivatingProjectService.getGraduationRequirementBySpecAndVersion()

        return res.toJSONString()
    }

    /**
     * 返回当前用户（学生）的毕业要求与指标点支撑关系对，包括指标点内容
     */
    @GetMapping("/requirementIndicator")
    fun getRequirementIndicator(): String {
        val res = JSONObject()

        res["code"] = 1
        res["msg"] = "success"
        res["result"] = cultivatingProjectService.getRequirementIndicator()

        return res.toJSONString()
    }

    /**
     * 返回指标点的支撑课程，及其支撑强度
     */
    @GetMapping("/indicatorCourse")
    fun getIndicatorCourse(): String {
        val res = JSONObject()

        res["code"] = 1
        res["msg"] = "success"
        res["result"] = cultivatingProjectService.getIndicatorCourse()

        return res.toJSONString()
    }
}